/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.ui.editors;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;

import edu.pku.sei.modeler.edit.parts.AbstractEditPartFactory;
import edu.pku.sei.modeler.edit.parts.AbstractTreeEditPartFactory;
import edu.pku.sei.modeler.images.ImageProvider;
import edu.pku.sei.modeler.model.structure.MetaDiagram;
import edu.pku.sei.modeler.project.AbstractModelingProject;
import edu.pku.sei.modeler.ui.palette.DiagramPaletteFactory;

/**
 * @author zl
 * 
 */
public class MetaModelEditorInput extends AbstractEditorInput implements IEditorInput {
	// XXX modified by ZSJ -- change Private to Protected
	protected MetaDiagram diagram;

	// XXX modified by ZSJ -- change Private to Protected
	protected DiagramPaletteFactory paletteFactory;

	// XXX modified by ZSJ -- change Private to Protected
	protected AbstractEditPartFactory partFactory;

	// XXX modified by ZSJ -- change Private to Protected
	protected AbstractTreeEditPartFactory treeFactory;

	// XXX modified by ZSJ -- change Private to Protected
	protected AbstractModelingProject project;

	// constructor
	public MetaModelEditorInput(AbstractEditPartFactory partFactory, AbstractTreeEditPartFactory treeFactory) {
		editID = "edu.pku.sei.modeler.ui.editors.MetaModelEditor";
		this.partFactory = partFactory;
		this.treeFactory = treeFactory;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IEditorInput#exists()
	 */
	public boolean exists() {
		return false;
	}

	public boolean equals(Object obj) {
		if (obj instanceof MetaModelEditorInput) {
			if (this.id != ((MetaModelEditorInput) obj).id)
				return false;
			else
				return true;
		} else
			return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
	 */
	public ImageDescriptor getImageDescriptor() {
		return ImageProvider.getImageDescriptor(ImageProvider.CLASS_IMAGE);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IEditorInput#getName()
	 */
	public String getName() {
		if (diagram != null)
			return diagram.getName();
		else
			return name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IEditorInput#getPersistable()
	 */
	public IPersistableElement getPersistable() {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IEditorInput#getToolTipText()
	 */
	public String getToolTipText() {
		return "MetaModel Editor Tips";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
	 */
	public Object getAdapter(Class adapter) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * @return Returns the diagram.
	 */
	public MetaDiagram getDiagram() {
		return diagram;
	}

	/**
	 * @param diagram
	 *            The diagram to set.
	 */
	public void setDiagram(MetaDiagram diagram) {
		this.diagram = diagram;
	}

	/**
	 * @return the paletteFactory
	 */
	public DiagramPaletteFactory getPaletteFactory() {
		return paletteFactory;
	}

	/**
	 * @param paletteFactory
	 *            the paletteFactory to set
	 */
	public void setPaletteFactory(DiagramPaletteFactory paletteFactory) {
		this.paletteFactory = paletteFactory;
	}

	/**
	 * @return the partFactory
	 */
	public AbstractEditPartFactory getPartFactory() {
		return partFactory;
	}

	/**
	 * @param partFactory
	 *            the partFactory to set
	 */
	public void setPartFactory(AbstractEditPartFactory partFactory) {
		this.partFactory = partFactory;
	}

	/**
	 * @return the treeFactory
	 */
	public AbstractTreeEditPartFactory getTreeFactory() {
		return treeFactory;
	}

	/**
	 * @param treeFactory
	 *            the treeFactory to set
	 */
	public void setTreeFactory(AbstractTreeEditPartFactory treeFactory) {
		this.treeFactory = treeFactory;
	}

	/**
	 * @return the project
	 */
	public AbstractModelingProject getProject() {
		return project;
	}

	/**
	 * @param project
	 *            the project to set
	 */
	public void setProject(AbstractModelingProject project) {
		this.project = project;
	}

}
